package com.ruoyi.web.controller.vantController.shopController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.construction.Team;
import com.ruoyi.system.domain.supe.HomeCarousel;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.gallery.HomeCarouselService;
import com.ruoyi.system.service.gallery.SubstationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api/home/comtroller")
@CrossOrigin
public class ApiHomeCarouselComtroller extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(ApiHomeCarouselComtroller.class);

    @Autowired
    private HomeCarouselService homeCarouselService;

    @Autowired
    private ISysDeptService sysDeptService;

    private String AppID = "wx5bf4dc4249222446"; //微信公众号的AppID
    private String AppSecret = "2032a97189d50632b3740af4f2d37c3c"; //微信公众号的AppSecret



    @GetMapping("/auth")
    public void auth(@RequestParam("code") String code) {
//        log.info("进入auth方法。。。");
//        log.info("code={}", code);

        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + AppID + "&secret=" + AppSecret + "&code=" + code + "&grant_type=authorization_code";

        RestTemplate restTemplate = new RestTemplate();
        String response = restTemplate.getForObject(url, String.class);
        log.info("response={}", response);
    }

    @GetMapping("/wx/wxLogin")
    public void doWxLogin (HttpServletRequest request, HttpServletResponse response) {

        try {
            homeCarouselService.doWxLogin(request, response);
            System.out.println("==================================>");
        } catch (Exception e) {
            e.printStackTrace();
            //相应的处理
        }

    }


    /**
     * 查询首页轮播图列表
     */
    @GetMapping("/findlistArea/{carouselArea}")
    public List<HomeCarousel> list(@PathVariable("carouselArea") String carouselArea)
    {
        List<HomeCarousel> list = homeCarouselService.findlistArea(carouselArea);
        return list;
    }

    // 查询部门
    @GetMapping("/finddeptname")
    public List<SysDept> finddeptname(SysDept sysDept){
        List<SysDept> sysDepts = sysDeptService.selectDeptName(sysDept);
        return sysDepts;
    }



}
